﻿/*
   这是执行自动更新的程序。
 * 1、下载的更新包必须放在程序目录之 Update 目录下，如 D35FLASH\PDADemo\Update\
 * 2、程序启动时，会检查 Update 目录下是否有更新包*.CAB文件，如果有，则执行更新
 
*/

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Loader
{
    static class Program
    {
        public static NLog.Logger logger = NLog.LogManager.GetLogger("Loader");

        #region P/Invoke
        [DllImport("coredll.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, int pvParam, uint fWinIni);

        [DllImport("coredll.dll")]
        public static extern IntPtr FindWindow([MarshalAs(UnmanagedType.LPWStr)]string lpClassName, [MarshalAs(UnmanagedType.LPWStr)]string lpWindowName);

        [DllImport("coredll.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        #endregion

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [MTAThread]
        static void Main()
        {
            Program.logger.Info("Loader start");

            #region Hide State Bar

            IntPtr hWnd = FindWindow("HHTaskBar", null);
            if (hWnd != IntPtr.Zero)
            {
                ShowWindow(hWnd, 0);
            }
            SystemParametersInfo(47, 0, 0, 0x0002);

            #endregion

            Application.Run(new UpdateForm());

            Program.logger.Info("Loader end");
        }
    }
}